{extend name="base"/}
{block name="main"}
<style>.btn {margin-bottom:0;}</style>
<div class="Hui-article">
    <article class="cl pd-20">
        <div class="n_tab_line">
            <a href="{:url('distribute/index')}" class="n_tab_list">单商品分销列表</a>
            <a href="{:url('distribute/add_share')}" class="n_tab_add" onclick="javascript:layer.msg('加载界面中,请稍等！',{icon:16,shade: 0.01});">
                <i class="Hui-iconfont">&#xe600;</i>添加分销商品
            </a>
            <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px;display: none;" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
            <div class="cl"></div>
        </div>
        <div>
            <style>.page_btn{float:left;}
            .tabBar span {background: #fff;color:#988989;font-size:14px;font-weight: normal;}</style>
            <div class="cl pd-5 bg-1 bk-gray mt-20">
                <form class="Huiform" method="post" action="__CONF_SITE__admin/distribute/index" style=" padding: 15px;">
                    <div class="text-c">
                        日期范围：
                        <input type="text" onfocus="WdatePicker()" value="{$star_time}" name="star_time" class="input-text Wdate" style="width:120px;">
                        -
                        <input type="text" onfocus="WdatePicker()" value="{$end_time}" name="end_time" class="input-text Wdate" style="width:120px;">
                        <input type="text" name="search_text" value="{$search_text}" placeholder=" 商品名称" style="width:250px" class="input-text">
                        <button class="btn btn-search radius" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜商品</button>
                    </div>
                </form>
            </div>
            <div class="cl pd-5 bg-1 bk-gray mt-20" style="padding:10px;border-bottom:0;margin-top: 15px;">
                <!--<span class="page_btn"><a href="javascript:;" onclick="goods_pldel()" class="btn btn-new radius"><i class="Hui-iconfont">&#xe6e2;</i> 删除</a></span>-->
                <div>
                <table class="table table-border table-bordered table-bg table-hover table-sort" style="margin-top: 0;">
                    <thead>
                    <tr class="text-c">
                        <th>缩略图</th>
                        <th>产品名称</th>
                        <th>单价</th>
                        {if $share['level']!=0}
                        <th>一级佣金</th>
                        {if $share['second']!=-1}
                        <th>二级佣金</th>{/if}
                        {if $share['third']!=-1}
                        <th>三级佣金</th>{/if}
                        {/if}
                        <th>添加时间</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="tbody">
                    {volist name="result" id="r" key="k"}
                    <tr class="text-c va-m">
                        <td><img width="60" height="60" class="radius" src="{$r['img_cover']}"></a></td>
                        <td class="text-l">{$r['goods_name']}</td>
                        <td><span class="price">{$r['price']} </span></td>
                       {if $share['level']!=0}
                        <td>{$r['first']} {$r['price_type']==0?'%':'元'}</td>
                        {if $share['second']!=-1}
                        <td>{$r['second']} {$r['price_type']==0?'%':'元'}</td>{/if}
                        {if $share['third']!=-1}
                        <td>{$r['third']} {$r['price_type']==0?'%':'元'}</td>{/if}
                        {/if}
                        <td>{:date('Y-m-d H:i:s',$r['create_time'])}</td>
                        <td class="td-status">
                            {if $r['status']==1}
                            <a onclick="goods_type_all(this,'{$r.id}','{$r.status}')" style="text-decoration:none" href="javascript:;" title="点击禁用"><span class="label label-secondary radius">已启用</span></a>
                            {else/}
                            <a onclick="goods_type_all(this,'{$r.id}','{$r.status}')" style="text-decoration:none" href="javascript:;" title="点击启用"> <span class="label label-danger radius">禁用</span></a>
                            {/if}
                        </td>
                        <td class="td-manage">
                            <a style="text-decoration:none;color:#0066cc;" class="ml-5" href="__CONF_SITE__admin/distribute/add_share&goods_id={$r.goods_id}" onclick="javascript:layer.msg('加载界面中,请稍等！',{icon:16,shade: 0.01});" title="编辑">
                                编辑
                            </a>
                            <a style="text-decoration:none;color:#0066cc;" class="ml-5" onClick="goods_del(this,'{$r.id}')" href="javascript:;" title="删除">删除
                            </a>
                       </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
                <div class="n_page_no">
                    {$page}
                </div>
            </div>
        </div>
        {/block}
        {block name="script"}
        <script type="text/javascript">
            /*
             参数解释：
             title	标题
             url		请求的url
             id		需要操作的数据id
             w		弹出层宽度（缺省调默认值）
             h		弹出层高度（缺省调默认值）
             */
            /*分销-状态修改*/
            function goods_type_all(obj,id,key) {
                //后台处理
                $.ajax({
                    type : "post",
                    url : "{:url('Distribute/share_type_all')}",
                    data : {
                        "id" : id,
                        "key" : key==1?2:1
                    },
                    success : function(data) {
                        if (data['code'] > 0) {
                            layer.msg('操作成功!',{icon: 1,time:500},function () {
                                window.location.reload();
                            });
                        }else{
                            layer.msg(data['message'], {icon: 2, time: 1000});
                        }
                    }
                })
            }
            /*商品-删除*/
            function goods_del(obj,id){
                layer.confirm('确认要删除该分销商品吗？',function(index){
                    //后台处理
                    $.ajax({
                        type : "post",
                        url : "{:url('Distribute/share_del')}",
                        data : { id : id.toString() },
                        dataType : "json",
                        success : function(data) {
                            if(data["code"] > 0 ){
                                $(obj).parents("tr").remove();
                                layer.msg(data['message'], {icon: 1, time: 1000});
                            }else {
                                layer.msg(data['message'], {icon: 2, time: 1000});
                            }
                        }
                    });
                });
            }
        </script>
        {/block}